﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.DependencyInjection;
using StyleMVVM.UnitTests.TestClasses.Conditions;

namespace StyleMVVM.UnitTests.DependencyInjection
{
	[TestClass]
	public class AttributeConditionTests : BaseTestClass
	{
		[TestMethod]
		public void GlobalConditionTest()
		{
			// Condition1
			Container.AddCondition(x => "Condition1");

			IInjectionContext injectionContext = Container.CreateInjectionContext();

			ImportObject importObject = Container.LocateWithContext<ImportObject>(injectionContext);

			Assert.IsNotNull(importObject);
			Assert.IsInstanceOfType(importObject.SomeInterface, typeof(SomeImpl1));
		}

		[TestMethod]
		public void TestOverrideTest()
		{
			// Condition1
			Container.AddCondition(x => "Condition1");

			IInjectionContext injectionContext = Container.CreateInjectionContext();

			ImportObject importObject = Container.LocateWithContext<ImportObject>(injectionContext);

			Assert.IsNotNull(importObject);
			Assert.IsInstanceOfType(importObject.SomeInterface, typeof(SomeImpl1));

			injectionContext = Container.CreateInjectionContext();

			injectionContext.RegisterExport(typeof(ISomeInterface), (x, y, z) => new SomeImpl2());

			importObject = Container.LocateWithContext<ImportObject>(injectionContext);

			Assert.IsNotNull(importObject);
			Assert.IsInstanceOfType(importObject.SomeInterface, typeof(SomeImpl2));
		}

		[TestMethod]
		public void ConditionTest()
		{
			// Condition1
			IInjectionContext injectionContext = Container.CreateInjectionContext();

			injectionContext.DefineCondition("Condition1");

			ImportObject importObject = Container.LocateWithContext<ImportObject>(injectionContext);

			Assert.IsNotNull(importObject);
			Assert.IsInstanceOfType(importObject.SomeInterface, typeof(SomeImpl1));

			// Condition2
			injectionContext = Container.CreateInjectionContext();

			injectionContext.DefineCondition("Condition2");

			importObject = Container.LocateWithContext<ImportObject>(injectionContext);

			Assert.IsNotNull(importObject);
			Assert.IsInstanceOfType(importObject.SomeInterface, typeof(SomeImpl2));

			// Condition3
			injectionContext = Container.CreateInjectionContext();

			injectionContext.DefineCondition("Condition3");

			importObject = Container.LocateWithContext<ImportObject>(injectionContext);

			Assert.IsNotNull(importObject);
			Assert.IsInstanceOfType(importObject.SomeInterface, typeof(SomeImpl3));
		}
	}
}